using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Babushka.GameModels;

namespace Babushka
{
    class LevelPlayer
    {
        private Level _level;
        private Camera cam;
        public bool IsRunning { get; set; }
        public bool IsPaused { get; set; }
        public Level Level
        {
            get
            {
                return this._level;
            }
            set
            {
                this._level = value;
            }
        }

        private Babushka.GameModels.Babushka player;

        public LevelPlayer()
        {
            IsRunning = false;
            IsPaused = true;
            cam = new Camera()
            {
                    Zoom = 0.95f,
            };
            player = new Babushka.GameModels.Babushka(new Vector2(10, 10));
        }

        public void Play(Level level)
        {
            this.Level = level;
            IsRunning = true;
            IsPaused = false;
        }

        public void TogglePause()
        {
            IsPaused = !IsPaused;
        }
        public void Update()
        {
            Level.Update();
            player.Update(Level);

        }
        public void Draw()
        {
            Game1.SpriteBatch.Begin(SpriteSortMode.BackToFront,
                        null,
                        null,
                        null,
                        null,
                        null,
                        cam.GetTransformation(Game1.Graphics.GraphicsDevice)); 
            for (int x = 0; x < Level.MapWidth; x++)
            {
                for (int y = 0; y < Level.MapHeight; y++)
                {
                    if (Level[x, y] == null)
                        continue;
                    Level[x, y].DrawTile(x, y);
                }
            }
            player.Draw();
            Game1.SpriteBatch.Draw(Babushka.Resources.Graphics.Target, player.Position - new Vector2(10), Color.Aqua);
            Game1.SpriteBatch.End();
        }
        public override string ToString()
        {
            return player.ToString();
        }
    }
}